package csl.blog.server.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.IdWorker;
import csl.blog.common.entity.Type;
import csl.blog.server.service.TypeService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @Description: TODO
 * @author: 隔山海
 * @date: 2021年07月15日 13:37
 */
@RequestMapping("type")
@RestController
@Slf4j
public class TypeController {

    @Autowired
    private TypeService typeService;

    @RequestMapping(value = "/add",method = RequestMethod.POST)
    public boolean add(@RequestBody Type type){
        type.setTypeId((int) IdWorker.getId());
       return typeService.save(type);
    }

    @RequestMapping(value = "/queryById",method = RequestMethod.GET)
    public List<Type> queryByCondition(@RequestBody Type type){
        LambdaQueryWrapper<Type> query = new LambdaQueryWrapper<>();
        query.eq(Type::getTypeId,type.getTypeId());
        return typeService.list(query);
    }
}
